#!/bin/bash
#
# Copyright (C) 2018 Western Digital Corporation or its affiliates.
#
# This file is released under the GPL.

scriptdir="$(cd "$(dirname "$0")" && pwd)"

for d in /sys/kernel/config/nullb/*; do [ -d "$d" ] && rmdir "$d"; done
modprobe -r null_blk
modprobe null_blk nr_devices=0 || exit $?
for d in /sys/kernel/config/nullb/*; do
    [ -d "$d" ] && rmdir "$d"
done
modprobe -r null_blk
[ -e /sys/module/null_blk ] && exit $?
modprobe null_blk nr_devices=0 &&
    cd /sys/kernel/config/nullb &&
    mkdir nullb0 &&
    cd nullb0 &&
    echo 1 > zoned &&
    echo 1 > zone_size &&
    echo 0 > completion_nsec &&
    echo 4096 > blocksize &&
    echo 1024 > size &&
    echo 1 > memory_backed &&
    echo 1 > power || exit $?

"${scriptdir}"/test-zbd-support "$@" /dev/nullb0
